<script>
import config from './config';
import { getToken } from '@/utils/auth';

export default {
  onLaunch: function () {
    this.initApp();
  },
  methods: {
    // 初始化应用
    initApp() {
      // 初始化应用配置
      this.initConfig();
      // 检查用户登录状态
      //#ifdef H5
      this.checkLogin();
      //#endif

      // #ifdef MP-WEIXIN
      this.getWinInfo();
      // #endif
    },
    initConfig() {
      this.globalData.config = config;
    },
    getWinInfo() {
      const systemInfo = uni.getSystemInfoSync();
      const statusBarHeight = systemInfo.statusBarHeight;
      const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
      const capsuleTop = menuButtonInfo.top;
      let navAllHeight = 0;
      if (systemInfo.platform === 'android') {
        navAllHeight = statusBarHeight + 48; // Android 导航栏高度
      } else {
        navAllHeight = statusBarHeight + 44; // iOS 导航栏高度
      }
      this.globalData.winInfo = {
        statusBarHeight,
        capsuleTop,
        navAllHeight
      };
    },
    checkLogin() {
      if (!getToken()) {
        this.$tab.reLaunch('/pages/login');
      }
    }
  }
};
</script>

<style lang="scss">
@import '@/static/scss/index.scss';
</style>
